Skip to content

fix(instagram): verify sessions without legacy query_hash, never password-login on throttles - #3

Merged
Pacman1984 merged 1 commit into
masterfrom
fix/instagram-session-check
Oct 26, 2026
Merged

Pacman1984 merged 1 commit into
masterfrom
fix/instagram-session-check

Conversation

@Pacman1984

Copy link
Copy Markdown
Owner

Summary

Two real extract instagram runs (15:36 and 20:03, 4.5 h apart) failed identically with 401 "Please wait a few minutes before you try again." on the legacy GraphQL query_hash d6f4427… — and, worse, silently fell back to a password login:

Changes

  • Session check (_check_session): no test_login(). Reads sessionid / ds_user_id locally (missing → logged out, no request), then one get_iphone_json("api/v1/users/<id>/info/") with max_connection_attempts=1 (restored in finally).
    • logged out (login redirect, login_required, other account) → password login if configured, else InstagramAuthRequired
    • checkpoint / challenge → InstagramAuthRequired, no password login
    • 401 / 429 / timeout / 5xx / unknown → new InstagramSessionCheckFailed (subclass of InstagramRateLimited, exit code 3), no password login, session file untouched
  • Saved feed via the private API api/v1/feed/saved/posts/ (lazy max_id pagination, stops on more_available=false, missing/repeated cursor, empty page); posts via Post.from_iphone_struct with a tolerant fallback node.
  • map_post reads owner, plain-int comment counts and carousel video children (with durations) from the private-API struct.
  • AbortDownloadException (checkpoint, login redirect) maps to InstagramAuthRequired.
  • Post.from_shortcode (transcription re-fetch) already uses a doc_id POST, unchanged.
  • Docs: troubleshooting note in docs/operations.md, CHANGELOG (Unreleased).

Test plan

  • uv run pytest: 994 passed, 4 skipped (was 964/4); new tests for throttled/logged-out/checkpoint/valid checks (password login never called on throttles, exactly one request, attempts restored), feed pagination/early stop/cursor loop, iphone-struct mapping, CLI exit code 3
  • three tests against a real InstaloaderContext with faked requests (no socket): throttled check = one GET; valid run only hits i.instagram.com/api/v1/…, never a query_hash
  • ruff check, ruff format --check, mypy src clean
  • Live check (not done, no requests to Instagram from this PR): after merge and a few hours' pause, postparse extract instagram --limit 1 --stop-after-known 1 (2 requests)

🤖 Generated with Claude Code

…word-login on throttles

The session check used instaloader's test_login(), which queries the legacy
GraphQL query_hash d6f4427... and turns every error, including Instagram's
401 "Please wait a few minutes" throttle, into "not logged in". The collector
then fell back to a scripted password login and rewrote the session file,
exactly what triggers checkpoints. The saved feed (Profile.own_profile() +
get_saved_posts()) used legacy query_hash queries as well.

- Session check: read the sessionid / ds_user_id cookies (missing: logged
  out, no request), then ask i.instagram.com api/v1/users/<id>/info/ once
  with max_connection_attempts temporarily set to 1. Only a positive
  "logged out" answer (login redirect, login_required, other account) falls
  back to the password login. Throttles, connection errors and unknown
  errors raise the new InstagramSessionCheckFailed (an InstagramRateLimited,
  exit code 3) and leave the session file untouched; checkpoints raise
  InstagramAuthRequired.
- Saved feed: private API api/v1/feed/saved/posts/ via get_iphone_json,
  paginated lazily with max_id, posts built with Post.from_iphone_struct
  (tolerant fallback node). map_post reads owner, comment count and carousel
  video children from the private API struct.
- translate_error maps AbortDownloadException checkpoints/login redirects to
  InstagramAuthRequired.
- Tests: fake loader records every request; real InstaloaderContext tests
  with a faked HTTP layer; CLI exit code 3 for a throttled check.
- Docs: operations troubleshooting note, CHANGELOG entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Pacman1984
Pacman1984 merged commit 904ceff into master Oct 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant